<template>
  <el-container>
    <el-form  :model="lhsxbData"  label-position="right" label-width="100px" style="width:100%;text-align: center"  ref="lhsxb" >
        <h3 :labelName="labelName">{{labelName}}</h3>
      <el-form-item label="物质编码" prop="1">
        <el-input v-model="lhsxbData.baseinfoWzbm"  :disabled="true"  ></el-input>
      </el-form-item>
      <el-form-item label="单位"  prop="2">
        <el-input v-model="lhsxbData.unit" :disabled="true"></el-input>
      </el-form-item>
      <el-form-item label="值" prop="3">
        <el-input v-model="lhsxbData.value"   placeholder="请输入内容"  ></el-input>
      </el-form-item>
      <el-form-item label="温度" prop="4">
        <el-input v-model="lhsxbData.temperature" placeholder="请输入内容" >
          <template slot="append">℃</template>
        </el-input>
      </el-form-item>
      <el-form-item label="压强" prop="5">
        <el-input v-model="lhsxbData.pa" placeholder="请输入内容"  >
          <template slot="append">Pa</template>
        </el-input>
      </el-form-item>
      <el-form-item label="实测/预测" prop="6">
        <el-input v-model="lhsxbData.shiceyuce" placeholder="请输入内容"  ></el-input>
      </el-form-item>
      <el-form-item label="数据来源" prop="7">
        <el-input v-model="lhsxbData.source" placeholder="请输入内容" ></el-input>
      </el-form-item>
      <el-form-item label="备注" prop="8">
        <el-input v-model="lhsxbData.remark" placeholder="请输入内容"  ></el-input>
      </el-form-item>
      <el-form-item prop="9">
        <el-button type="primary" style="margin-top: 12px;" @click="method" :btName="btName" >{{btName}}</el-button>
      </el-form-item>
    </el-form>
  </el-container>
</template>

<script>
    export default {
      name: "Lhsxb",
      props: {
        elementId: {
          type: String,
          default: ''
        },
        perms: '',
        labelName:'',
        btName:'',
        showdata:{}
      },
      data() {
        return {
          lhsxbData: {
            'attribute':'',
            'baseinfoWzbm': '',
            'id': '',
            'unit': '',
            'value': '',
            'temperature': '',
            'pa': '',
            'shiceyuce': '',
            'source': '',
            'remark': '',
            'flag': '',
            'lastid': ''
          },
          findParams:{
            elementId:'',
            labelName:'',
            flag:''
          },
          addParams:{
            labelName:''
          },
        }
      },
      watch: {
        elementId(value) {
        }
      },
      mounted() {
        console.log('elementID:' + this.elementId)
        console.log(this.perms)
        this.$nextTick(()=>{
          this.$refs['lhsxb'].resetFields()}
        )
        console.log(this.showdata)
        this.lhsxbData=this.showdata
      },
      methods: {
        // queryElement: function () {
        //   this.findParams.elementId=this.elementId
        //   this.findParams.labelName=this.labelName
        //   this.findParams.flag = 1
        //   this.$api.addrecord.findByIdAndFlagInLhsxb(this.findParams).then(res => {
        //         this.lhsxbData = res.data[0]
        //   })
        // },
        modifyId:function(){
          this.lhsxbData.id=this.perms+Date.now()
        },
        modifyAuthority:function(){
          if(this.perms==='admin'){
            this.lhsxbData.flag=1
          }else{
            if(this.btName==="新增") {
              this.lhsxbData.flag=0
            }else{
              this.lhsxbData.flag=2
            }
          }
        },
        save:function() {
          this.modifyAuthority()
          this.addParams.labelName=this.labelName
          if(this.btName ==="新增") {
            this.modifyId()
            this.$api.addrecord.addRecordInLhsxb(this.lhsxbData, this.addParams).then(res => {
              alert("新增成功！")
            })
          } else{
            this.lhsxbData.lastid=this.lhsxbData.id
            this.modifyId()
            this.$api.addrecord.addRecordInLhsxb(this.lhsxbData, this.addParams).then(res => {
              alert("纠错成功！待审核")
            })
            }

        },
        update:function () {
          this.modifyAuthority()
          this.$api.addrecord.updateInLhsxb(this.lhsxbData).then(res => {
            alert("更新成功！")})
        },
        method:function () {
          if(this.btName==="更新"){
            this.update()
          }else {
            this.save()
          }
        }
      }
      }

</script>

<style scoped>

</style>
